#include "ImpPlaneObject.h"
#include "Vector3.h"
#include <iostream>

ImpPlaneObject::ImpPlaneObject(Vector3 pos, Vector3 norm) : _normal(Vector3::normalize(norm))
{
    _d = 1.0 * Vector3::dot(pos, _normal);
    InitObject("ImpPlaneObject");
}

bool ImpPlaneObject::Intersects(Ray ray, Vector3& location)
{

 //   std::cout << ray.direction << std::endl;
  //  std::cout << "normal: " << _normal << std::endl;

    if (Vector3::dot(_normal, ray.direction) > 0.0)
        return false;


    float t = (_d - Vector3::dot(_normal, ray.start)) / Vector3::dot(_normal, ray.direction);


    location = t * ray.direction + ray.start;
 //   std::cout << Vector3::dot(_normal, ray.direction) << std::endl;


    if (t != t || t < 0.0)
        return false;
    else {
//        std::cout << t << std::endl;
//        std::cout << "true" << std::endl;
        return true;
    }
}

Vector3 ImpPlaneObject::GetNormal(Vector3 location)
{
    return _normal;
}

float ImpPlaneObject::DistanceToPointPow2(Vector3 p)
{
    return 0;
}
